#include "commandmapper.h"
#include "CommandHandler.h"

CommandMapper* CommandMapper::instance()
{
	static CommandMapper* commandMapper = new CommandMapper();
	return commandMapper;
}

CommandMapper::CommandMapper()
{
	m_CodeToFunc.insert(0x01, PlayStoreFileHandler);
	m_CodeToFunc.insert(0x02, SendFileHandler);
	m_CodeToFunc.insert(0x03, KeepAliveHandler);
	m_CodeToFunc.insert(0x04, VolumePlanHandler);
	m_CodeToFunc.insert(0x05, RealtimePlayHandler);
	m_CodeToFunc.insert(0x06, StopRealtimePlayHandler);
	m_CodeToFunc.insert(0x30, CorrectTimeHandler);
	m_CodeToFunc.insert(0x31, LEDHandler);
	m_CodeToFunc.insert(0x32, PanTiltCtrlHandler);
	m_CodeToFunc.insert(0x33, DeviceControlHandler);
	m_CodeToFunc.insert(0x34, PowerControlHandler);
	m_CodeToFunc.insert(0x40, FileBrowserHandler);
	m_CodeToFunc.insert(0x41, RestartClientHandler);
	m_CodeToFunc.insert(0x42, SetSplitModeHandler);
}

bool CommandMapper::handleCommand(unsigned long commandCode, int socket, int commandLength)
{
	if(!m_CodeToFunc.contains(commandCode))
	{
		return DummyHandler(socket, commandLength);
	}
	return m_CodeToFunc.value(commandCode)(socket, commandLength);
}
